#ifndef GLOBALVARIABLE_H
#define GLOBALVARIABLE_H

#include <sys/time.h>
#include <stdlib.h>

/*
这里存放着所有的全局变量，模拟C++创建一个单例
*/

#define MAXBUFFERSIZE 1024
#define CONNECTION_SIZE 1048576
#define MAX_PORTS 20
#define TIME_SUB_MS(tv1, tv2) ((tv1.tv_sec - tv2.tv_sec) * 1000 + (tv1.tv_usec - tv2.tv_usec) / 1000)

typedef int (*rcallback)(int fd);

enum _EPOLL_CTRL
{
    ADD,
    MOD
};

struct conn
{
    int fd;
    char rbuffer[MAXBUFFERSIZE];
    int rlength;
    char wbuffer[MAXBUFFERSIZE];
    int wlength;
    int status;//状态机
    rcallback send_callback;
    union
    {
        rcallback recv_callback;
        rcallback accept_callback;
    } r_action;
};

typedef struct globalVariable
{
    int epfd;//epoll返回值
    struct timeval begin;
    unsigned short startPort;//监听的第一个端口
    unsigned short listenNumber;//监听端口数量
    struct conn conn_list[CONNECTION_SIZE];
}Singleton;

static Singleton *g_pVariableC = NULL;
Singleton* GetInstance();

#endif